/* MOS                                                        */
/* Giordano Mion, Luca David Opromolla and Alessandro Sforza  */
/* University of Sussex, Banco de Portugal & NC State, and Bologna       */


program drop _all
clear
clear matrix
***capture log close
set more off
local path = "/Users/lucadavidopromolla/Projects/MOS_rev"
***cd "/Users/alessandrosforza/Dropbox/MOS - INE data/data/trade"
cd "`path'/data/trade"
***log using "`path'/logs/MOS_Rauch_Jun_23_21_ine.log",replace
***set more off
clear
set mem 15g



use "`path'/computation/Tdata.dta",clear
gen double hs6 = int(nc/100)
collapse (sum) v_est,by(npc_alt ano fluxo pais hs6)
reshape wide v_est, i(npc_alt ano pais hs6) j(fluxo)
recode v_est* (.=0)
// Deflation (using Statistics Portugal, Consumer Price index - Consumer Price index (CPI - Base 2008) by Special aggregates; Monthly, aggregated by us to Yearly
local vars "v_est2"
foreach l of local vars {
replace `l' = `l'/0.584620553146 if ano==1991
replace `l' = `l'/0.640505339145 if ano==1992
replace `l' = `l'/0.683956232057 if ano==1993
replace `l' = `l'/0.721030329678 if ano==1994
replace `l' = `l'/0.751476569923 if ano==1995
replace `l' = `l'/0.774539960416 if ano==1996
replace `l' = `l'/0.792638102195 if ano==1997
replace `l' = `l'/0.813031926393 if ano==1998
replace `l' = `l'/0.832061165223 if ano==1999
replace `l' = `l'/0.855797365841 if ano==2000
replace `l' = `l'/0.893194773542 if ano==2001
replace `l' = `l'/0.92535329307 if ano==2002
replace `l' = `l'/0.955142075833 if ano==2003
replace `l' = `l'/0.97773314449 if ano==2004
replace `l' = `l'/1 if ano==2005
replace `l' = `l'/1.031072992224 if ano==2006
}
collapse (sum) v_est2 ,by(hs6)
drop if hs6==.
egen double share = pc(v_est2), prop
keep hs6 share
sort hs6
save "`path'/computation/P1rauch.dta",replace


